package com.zzyl.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    //查询所有
    @Override
    public List<NursingLevelVo> listAll() {
      List<NursingLevelVo> nursingLevelVos=nursingLevelMapper.listAll();
        return nursingLevelVos;
    }

    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel=new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public PageResponse<NursingLevelVo> getNursingLevel(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo> nursingLevels=nursingLevelMapper.getNursingLevel(name,status);
        PageResponse<NursingLevelVo> pageResponse=new PageResponse<>(nursingLevels);
        pageResponse.setRecords(nursingLevels.getResult());
          return pageResponse;
    }

    @Override
    public NursingLevelVo getNursingLevelById(Long id) {
        NursingLevelVo nursingLevelVo=nursingLevelMapper.getNursingLevelById(id);
        return nursingLevelVo;
    }

    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
           NursingLevel nursingLevel=new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    @Override
    public void deleteNursingLevel(Long id) {
        nursingLevelMapper.deleteNursingLevel(id);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingLevelMapper.updateStatus(id,status);
    }


}
